package com.cw.jeeyt.service.converter.system;

import java.util.ArrayList;
import java.util.List;

import com.cw.jeeyt.service.bo.system.SystemDictCacheBo;
import com.google.common.collect.Iterators;
import com.google.common.collect.Lists;
import com.cw.jeeyt.service.bo.system.SystemDictBo;
import com.cw.jeeyt.dao.model.system.SystemDictDo;
import com.cw.lang.common.utils.CollectionUtil;

/**
 * 数据字典信息转换类
 *
 * @author chenw
 * @date 2019-03-10 13:04:25
 */
public class SystemDictConverter {

    /**
     * do转bo
     *
     * @param model
     * @return
     */
    public static SystemDictBo do2Bo(SystemDictDo model) {
        if (model == null) {
            return null;
        }
        SystemDictBo bo = new SystemDictBo();
        bo.setId(model.getId());
        bo.setParentId(model.getParentId());
        bo.setItemName(model.getItemName());
        bo.setItemValue(model.getItemValue());
        bo.setItemCode(model.getItemCode());
        bo.setCreateBy(model.getCreateBy());
        bo.setCreateDate(model.getCreateDate());
        bo.setUpdateBy(model.getUpdateBy());
        bo.setUpdateDate(model.getUpdateDate());
        bo.setDictComment(model.getDictComment());
        return bo;
    }
    /**
     * do转bo
     *
     * @param model
     * @return
     */
    public static SystemDictCacheBo do2CacheBo(SystemDictDo model) {
        if (model == null) {
            return null;
        }
        SystemDictCacheBo bo = new SystemDictCacheBo();
        bo.setId(model.getId());
        bo.setParentId(model.getParentId());
        bo.setItemName(model.getItemName());
        bo.setItemValue(model.getItemValue());
        bo.setItemCode(model.getItemCode());
        bo.setDictComment(model.getDictComment());
        return bo;
    }
    /**
     * bo转do
     *
     * @param bo
     * @return
     */
    public static SystemDictDo bo2Do(SystemDictBo bo) {
        if (bo == null) {
            return null;
        }
        SystemDictDo model = new SystemDictDo();
        model.setId(bo.getId());
        model.setParentId(bo.getParentId());
        model.setItemName(bo.getItemName());
        model.setItemValue(bo.getItemValue());
        model.setItemCode(bo.getItemCode());
        model.setCreateBy(bo.getCreateBy());
        model.setCreateDate(bo.getCreateDate());
        model.setUpdateBy(bo.getUpdateBy());
        model.setUpdateDate(bo.getUpdateDate());
        model.setDictComment(bo.getDictComment());
        return model;
    }

    /**
     * doList转boList
     *
     * @param doList
     * @return
     */
    public static List<SystemDictBo> doList2BoList(List<SystemDictDo> doList) {
        if (CollectionUtil.isEmpty(doList)) {
            return new ArrayList<>();
        }
        return Lists.newArrayList(Iterators.transform(doList.iterator(), SystemDictConverter::do2Bo));
    }

    /**
     * boList转doList
     *
     * @param boList
     * @return
     */
    public static List<SystemDictDo> boList2DoList(List<SystemDictBo> boList) {
        if (CollectionUtil.isEmpty(boList)) {
            return new ArrayList<>();
        }
        return Lists.newArrayList(Iterators.transform(boList.iterator(), SystemDictConverter::bo2Do));
    }

    public static ArrayList<SystemDictCacheBo> doList2CacheBoList(List<SystemDictDo> list) {
        if (CollectionUtil.isEmpty(list)) {
            return new ArrayList<>();
        }
        return Lists.newArrayList(Iterators.transform(list.iterator(), SystemDictConverter::do2CacheBo));
    }
}